layui.use(['layer', 'form', 'admin', 'laydate', 'ax','layarea','upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var layer = layui.layer;
    var layarea = layui.layarea;
    var upload = layui.upload;
    var path = "https://exam-1257801634.cos.ap-chengdu.myqcloud.com/";
    var examUser;
    new $ax(Feng.ctxPath + "/api/exam/getExamUserInfoByCode?studentCode="+Feng.getUrlParam("student_code"), function (data){
        if(data.data){
            $("#userId").val(data.data.user_id);
            $("#full_name").val(data.data.full_name);
            $("#name").val(data.data.name);
            $("#school_name").val(data.data.school_name);
            $("#student_code").val(data.data.student_code);
        }
    }).start();
    new $ax(Feng.ctxPath + "/exam/examResulInfo?examResultUserId="+Feng.getUrlParam("examResultUserId"), function (data){
        if(data.data){
            $("#examResultUserId").val(data.data.exam_result_user_id);
            $("#admission_card_no").val(data.data.admission_card_no);
            $("#exam_title").val(data.data.exam_title);
            $("#exam_content").val(data.data.exam_text+"/"+data.data.exam_time);
            $("#examResult").val(data.data.exam_result);
            if(data.data.exam_work){
                $("#examWork").val(data.data.exam_work);
                data.data.exam_work.split(",").forEach(work=>{
                    $('#demo2').append('<img src="'+ path+work +'" alt="'+ work +'" class="layui-upload-img" style="width: 20%">')
                })
            }
        }
    }).start();

//多图片上传
    var imgUrls1 = [];
    upload.render({
        elem: '#test2',
        url: Feng.ctxPath + '/api/upload/uploadFile',
        multiple: true,
        before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" style="width: 20%">')
            });
        },
        done: function(res){
            //上传完毕
            //如果上传失败
            if (res.code != 200) {
                return layer.msg('上传失败');
            }
            imgUrls1.push(res.data.fileName);
            $("#examWork").val(imgUrls1.toLocaleString());
            //上传成功
        }
    });

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/exam/examResulSave", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
    });

});